package com.infore.dataReceiving.core.filter.instructions;
import com.infore.dataReceiving.core.chain.Water2018InstructionsChain;
import com.infore.dataReceiving.core.enums.Water2018InstructionsTypeEnum;
import com.infore.dataReceiving.core.enums.ResponseEnum;
import com.infore.dataReceiving.core.filter.Water2018InstructionsFilter;
import com.infore.dataReceiving.dto.WaterInstructionsDto;
import com.infore.dataReceiving.repository.IBackControlLogRepository;
import com.infore.dataReceiving.util.RedisUtil;
import io.netty.channel.ChannelHandlerContext;

/**
 * 返回请求应答
 * @author 69457
 *
 */
public class ResponseFilter implements Water2018InstructionsFilter{
	
	@Override
	public void doFilter(ChannelHandlerContext ctx,WaterInstructionsDto dto, 
			Water2018InstructionsChain chain,RedisUtil redisUtil,IBackControlLogRepository repository, boolean interrupt) {
		if(Water2018InstructionsTypeEnum.water2018_9011.getCn().equals(dto.getCn())) {
			interrupt = true;
			try {
				System.out.println("正在更新返回请求应答！！！！！！！！！！！！！");
				String qnRtn = dto.getQnRtn();
				String response = "";
				if(ResponseEnum.response_1.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_1.getMsg();
				}else if(ResponseEnum.response_2.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_2.getMsg();
				}else if(ResponseEnum.response_3.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_3.getMsg();
				}else if(ResponseEnum.response_4.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_4.getMsg();
				}else if(ResponseEnum.response_5.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_5.getMsg();
				}else if(ResponseEnum.response_6.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_6.getMsg();
				}else if(ResponseEnum.response_7.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_7.getMsg();
				}else if(ResponseEnum.response_8.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_8.getMsg();
				}else if(ResponseEnum.response_9.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_9.getMsg();
				}else if(ResponseEnum.response_10.getCode().equals(qnRtn)) {
					response = ResponseEnum.response_10.getMsg();
				}else {
					response = "未知错误！！";
				}
				String mn = dto.getMn();
				String qn = dto.getQn();
				repository.updateResponseFlag(response,mn, qn);
			} catch (Exception e) {
				System.out.println("更新返回请求应答错误：");
			}
		}
		chain.doFilter(ctx,dto,chain,redisUtil,repository,interrupt);
	}
	
}
